//
//  ViewController.m
//  ChartOfSsy
//
//  Created by 汤天明 on 2018/6/26.
//  Copyright © 2018年 汤天明. All rights reserved.
//

#import "ViewController.h"
#import "ChartCell.h"
#import "AAChartModel.h"
#import "AAChartKit.h"
#import "AAGlobalMacro.h"
@interface ViewController ()

@property (nonatomic,copy) NSArray *dataSource;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.tableView.rowHeight = 300;
    self.dataSource = @[AAChartTypeColumn,AAChartTypeBar,AAChartTypeLine,AAChartTypeSpline,AAChartTypeArea,AAChartTypeAreaspline,AAChartTypeBubble,AAChartTypeColumn,AAChartTypeLine,AAChartTypeSpline,AAChartTypeArea,AAChartTypeAreaspline,AAChartTypeBubble,AAChartTypeColumn,AAChartTypeLine,AAChartTypeSpline,AAChartTypeArea,AAChartTypeAreaspline,AAChartTypeBubble];
    [self.tableView reloadData];
    // Do any additional setup after loading the view, typically from a nib.
}


- (AAChartModel *)configureAAChartModel {
    AAChartModel *aaChartModel= AAObject(AAChartModel)
    .chartTypeSet(AAChartTypeColumn)//图表类型
    .titleSet(@"")//图表主标题
    .subtitleSet(@"")//图表副标题
    .yAxisVisibleSet(true)//设置 Y 轴是否可见
    .colorsThemeSet(@[@"#9b43b4",@"#ef476f",@"#ffd066",@"#04d69f",@"#25547c",])//设置主体颜色数组
    .yAxisTitleSet(@"")//设置 Y 轴标题
    .tooltipValueSuffixSet(@"℃")//设置浮动提示框单位后缀
    .backgroundColorSet(@"#ffffff")
    .yAxisGridLineWidthSet(@0)//y轴横向分割线宽度为0(即是隐藏分割线)
    .stackingSet(AAChartStackingTypeNormal)
    .borderRadiusSet(@5)
    .seriesSet(@[
                 AAObject(AASeriesElement)
                 .nameSet(@"2017")
                 .dataSet(@[@7.0, @6.9, @9.5, @14.5, @18.2, @21.5, @25.2, @26.5, @23.3, @18.3, @13.9, @9.6]),
                 AAObject(AASeriesElement)
                 .nameSet(@"2018")
                 .dataSet(@[@0.2, @0.8, @5.7, @11.3, @17.0, @22.0, @24.8, @24.1, @20.1, @14.1, @8.6, @2.5]),
                 AAObject(AASeriesElement)
                 .nameSet(@"2019")
                 .dataSet(@[@0.9, @0.6, @3.5, @8.4, @13.5, @17.0, @18.6, @17.9, @14.3, @9.0, @3.9, @1.0]),
                 AAObject(AASeriesElement)
                 .nameSet(@"2020")
                 .dataSet(@[@3.9, @4.2, @5.7, @8.5, @11.9, @15.2, @17.0, @16.6, @14.2, @10.3, @6.6, @4.8]),
                 ]
               );
    return aaChartModel;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ChartCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    if (cell == nil) {
        cell = [[ChartCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"];
    }
    AAChartModel *model = [self configureAAChartModel];
    model.chartType = self.dataSource[indexPath.row];
    [cell refreshWithChartModel:model];
    return cell;
}
@end
